# -*- coding: utf-8 -*-

from bopress.hook import add_static_path, add_menu_page, add_action

plugin_name = "Gallery Demo"
version = "1.0"
description = "一个具有独立结构的相册样例"
uri = "http://www.xianduoji.cn"
author = "yezang"
author_uri = "http://www.xianduoji.cn"
__author__ = 'yezang'


def scripts(res, current_screen):
    if current_screen.id == "gallery-demo":
        res.enqueue_plugin_script(src="gallerydemo/static/js/jquery.justifiedGallery.min.js", ver="3.6.3")


def styles(res, current_screen):
    if current_screen.id == "gallery-demo":
        res.enqueue_plugin_style(src="gallerydemo/static/css/justifiedGallery.min.css", ver="3.6.3")


def data(handler):
    items = [
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730822580.ajpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730820177.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730824996.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730827161.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730829663.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730832079.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730833246.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730835661.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730837995.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730840412.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730842746.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730845162.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730847578.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730849996.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730853578.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730854745.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730857162.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730859578.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730861995.jpg",
        "http://img.pconline.com.cn/images/upload/upc/tx/ladyproduct/1702/22/c0/37883495_1487730864497.jpg"
    ]
    html = list()
    for v in items:
        h = """
        <a href="{0}"><img alt="相册样例" src="{0}"/></a>
        """.format(v, v)
        html.append(h)
    handler.render_json("".join(html))


def bo_plugin_load():
    add_static_path("gallerydemo/static")
    add_menu_page("Gallery Demo", "Gallery Demo", "gallery-demo", ["read"],
                  "gallerydemo/tpl/gallery.html")
    add_action("bo_enqueue_styles", styles)
    add_action("bo_enqueue_scripts", scripts)
    add_action("bo_api_get_gallery_demo_data", data)
